home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_100
/
129_01
/
210rooma.c
< prev
next >
Wrap
Text File
|
1985-03-09
|
22KB
|
746 lines
/************************************************************************/
/* rooma.c */
/* room code for Citadel bulletin board system */
/************************************************************************/
/************************************************************************/
/* history */
/* */
/* 84Dec20 HAW&JLS The vp union eliminated from the system. */
/* 84Sep16 HAW #if put in to handle CP/M-85 bug. */
/* 84Aug23 JLS & HAW JLS's <F>orget Room Scheme implemented. */
/* 84Jul12 JLS & HAW gotoRoom() and dumpRoom() modified for <S>kip. */
/* 84Jun23 HAW Files now checked for CP/M R/O status. */
/* 84Jun23 HAW & JLS Unused locals are zapped */
/* 84Apr04 HAW Start 1.50a update */
/* 83Feb24 Insert check for insufficient RAM, externs too low. */
/* 82Dec06 CrT 2.00 release. */
/* 82Nov05 CrT main() splits off to become citadel.c */
/************************************************************************/
#include <210ctdl.h>
/************************************************************************/
/* Contents */
/* */
/* dumpRoom() tells us # new messages etc */
/* fileDir() prints out a filename for a dir listing */
/* fillMailRoom() set up Mail> from log record */
/* gotoRoom() handles "g(oto)" command for menu */
/* init() system startup initialization */
/* initCitadel() */
/* initSysop() */
/* listRooms() lists known rooms */
/* openFile() opens a .sys file */
/* readSysTab() restores system state from citadel.tab */
/* roomExists() returns slot# of named room else ERROR */
/* setSpace() set default disk and user# */
/* setUp() */
/* systat() shows current system status */
/* wildCard() expands ambiguous filenames */
/* writeSysTab() saves state of system in citadel.tab */
/* */
/************************************************************************/
/************************************************************************/
/* dumpRoom() tells us # new messages etc */
/************************************************************************/
dumpRoom()
{
char hasSkipped, str[NAMESIZE];
int fileDir();
int i, count, loc, newCount, no;
for (newCount=0, count=0, i=0; i<MSGSPERRM; i++) {
loc = roomBuf.msg[i].rbmsgLoc;
no = roomBuf.msg[i].rbmsgNo ;
if (loc != ERROR) {
/* comparisons which take 64K wraparound into account: */
if (no - oldestLo
< 0x8000
) {
count++;
}
/* don't boggle -- just checking against newestLo as of */
/* the last time we were in this room: */
if (no -
(logBuf.lbvisit[ logBuf.lbgen[thisRoom] & CALLMASK ]+1)
< 0x8000
) {
newCount++;
}
}
}
/* lazy patch: */
if (newCount > count) newCount = count;
mPrintf(" %d messages\n ", count);
if (loggedIn && newCount > 0) mPrintf(" %d new\n", newCount);
if ((roomBuf.rbflags & CPMDIR) && !expert) {
/* list directory also: */
doCR();
wildCard(fileDir, "*.*");
}
for (i = LOBBY, hasSkipped = FALSE; i < MAXROOMS; i++)
if (roomTab[i].rtflags & INUSE &&
roomTab[i].rtgen == (logBuf.lbgen[i] >> GENSHIFT)) {
if (roomTab[i].rtflags & SKIP)
hasSkipped = TRUE;
else
if (roomTab[i].rtlastMessage - (
logBuf.lbvisit[logBuf.lbgen[i] & CALLMASK] + 1)
< 0x8000)
break;
}
if (i == MAXROOMS && hasSkipped) {
mPrintf("\n Skipped rooms: \n ");
for (i = LOBBY; i < MAXROOMS; i++) /* No need to match gen #s. */
if (roomTab[i].rtflags & SKIP &&
roomTab[i].rtflags & INUSE) {
roomTab[i].rtflags &= ((BYTE - 1) - SKIP); /* Clear. */
strcpy(str, roomTab[i].rtname);
if (roomTab[i].rtflags & CPMDIR) strcat(str, ":");
else strcat(str, ">");
if (!(roomTab[i].rtflags & PUBLIC)) strcat(str, "*");
mPrintf(" %s ", str);
}
}
}
/************************************************************************/
/* fileDir() prints out one filename and size, for a dir listing */
/************************************************************************/
fileDir(fileName)
char *fileName;
{
struct fcb block;
char tempName[NAMESIZE], tBuf[2*NAMESIZE];
outFlag = OUTOK;
unspace(fileName, tempName);
setFcb(&block, tempName);
bdos(GETfILEsIZE, &block); /* very slow on MMS BIOS! */
FDSectCount += block.fcbRecn;
sprintf(tBuf, "%s%5d ", fileName, block.fcbRecn);
putWord(tBuf);
mAbort(); /* chance to next(!)/pause/skip */
}
/************************************************************************/
/* fillMailRoom() */
/************************************************************************/
fillMailRoom()
{
int i;
/* mail room -- copy messages in logBuf to room: */
for (i=0; i<MSGSPERRM; i++) {
roomBuf.msg[i].rbmsgLoc = ERROR;
roomBuf.msg[i].rbmsgNo = ERROR;
}
for (i=0; i<MAILSLOTS; i++) {
if (i==MSGSPERRM) break; /* for MSGSPRRM < MAILSLOTS */
roomBuf.msg[i].rbmsgLoc = logBuf.lbslot[i];
roomBuf.msg[i].rbmsgNo = logBuf.lbId[i] ;
}
noteRoom();
}
/************************************************************************/
/* gotoRoom() is the menu fn to travel to a new room */
/* returns TRUE if room is Lobby>, else FALSE */
/************************************************************************/
char gotoRoom(nam, mode)
char *nam, mode;
{
int i, foundit, newStuff, nWest, roomNo;
if (strLen(nam) == 0) {
/* update log entry for current room: */
if (mode != 'S') {
logBuf.lbgen[thisRoom] = roomBuf.rbgen << GENSHIFT;
/* Clear SKIP bit */
roomTab[thisRoom].rtflags &= ((BYTE - 1) - SKIP);
}
foundit = FALSE; /* leaves us in Lobby> if nothing found */
newStuff= FALSE;
for (i = 0
;
i<MAXROOMS && !foundit
;
i++
) {
if (
(roomTab[i].rtflags & INUSE)
&&
(roomTab[i].rtgen == (logBuf.lbgen[i] >> GENSHIFT) || aide)
&&
(roomTab[i].rtflags & SKIP) == 0
) {
nWest = logBuf.lbvisit[logBuf.lbgen[i] & CALLMASK]+1;
if (roomTab[i].rtlastMessage - nWest < 0x8000) {
if (i != thisRoom && (i != AIDEROOM || aide)) {
foundit = i;
newStuff= TRUE;
}
}
}
}
getRoom(foundit);
mPrintf("%s\n ", roomBuf.rbname);
} else {
/* non-empty room name, so now we look for it: */
if (
(roomNo = roomExists(nam)) == ERROR
||
(roomNo==AIDEROOM && !aide)
) {
mPrintf(" ?no %s room\n", nam);
} else {
/* update log entry for current room: */
if (mode != 'S') {
if (loggedIn)
logBuf.lbgen[thisRoom] = roomBuf.rbgen << GENSHIFT;
roomTab[thisRoom].rtflags &= ((BYTE - 1) - SKIP);
}
getRoom(roomNo);
/* if may have been unknown... if so, note it: */
if ((logBuf.lbgen[thisRoom] >> GENSHIFT) != roomBuf.rbgen) {
logBuf.lbgen[thisRoom] = (
(roomBuf.rbgen << GENSHIFT) +
(MAXVISIT -1)
);
}
}
}
setUp(FALSE);
dumpRoom();
return newStuff; /* was thisRoom */
}
/************************************************************************/
/* init() -- master system initialization */
/************************************************************************/
init() {
char getCh(), readSysTab(), toUpper();
char *msgFile;
unsigned codend(), endExt(), externs(), topOfMem();
int getText(); /* Forces load in BDS C 1.50a */
whichIO = CONSOLE;
if (!readSysTab()) exit();
setSpace(homeDisk, homeUser);
/* 1K RAM might not actually be sufficient... */
if (topOfMem() - codEnd() < 1024) {
printf("Not enough RAM!");
exit();
}
if (codEnd() > externs()) {
printf("Externs too low!");
exit();
}
#ifdef XYZZY
printf("code ends ....at %u\n", codend() );
printf("externs start at %u\n", externs() );
printf("externs end at %u\n", endext() );
printf("free RAM ends at %u\n", topofmem());
#e